<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/platform/losys/logistics/order"  data-pjax id="goback"><i class="ti-angle-left"></i> 返回</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="orderAddForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/losys/taobao/order/addDo" method="post">
                <div class="row mb10">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">买家会员名</label>

                            <div class="col-sm-8">
                                <input type="text" id="account" class="form-control" name="account" data-parsley-required="true"
                                       placeholder="买家会员名" maxlength="30">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="unitcode" class="col-sm-2 control-label">收货人姓名</label>

                            <div class="col-sm-8">
                                <input type="text" id="recipient" class="form-control" name="recipient" data-parsley-required="true"
                                       placeholder="收货人姓名" maxlength="30">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="note" class="col-sm-2 control-label">联系电话</label>

                            <div class="col-sm-8">
                                <input type="text" id="fixedTelephone" class="form-control" name="fixedTelephone" placeholder="联系电话"
                                data-parsley-pattern="(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)" maxlength="14">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="address" class="col-sm-2 control-label">联系手机</label>

                            <div class="col-sm-8">
                                <input type="text" id="mobilePhone" name="mobilePhone" class="form-control" data-parsley-required="true"
                                 placeholder="联系手机" data-parsley-pattern="(^0{0,1}1[3-8][0-9]{9}$)" maxlength="11">
                            </div>
                        </div>
                        <!-- <div class="form-group">
                            <label for="telephone" class="col-sm-2 control-label">收货地址</label>

                            <div class="col-sm-8">
                                <input type="text" id="address" name="address" class="form-control"  data-parsley-required="true"
                                placeholder="收货地址" maxlength="35">
                            </div>
                        </div> -->
                        <div class="form-group">
	                            	<label for="name" class="col-sm-2 control-label">省份</label>
	
	                            	<div class="col-sm-8">
	                                <select id="sheng" name="sheng" class="form-control" onchange="shengfen()" >
	                                	<% if(!isEmpty(areaOne)) {%>
						        		<% for(area1 in areaOne){ %>	
										     <option value=${area1.id!} >${area1.name!}</option>
										<%}%>
										<%}%>	
						        	</select>
						        	<input type="hidden" id="area" name="area" class="form-control" value="">
                            		</div>
                        	</div>
                        	
                        	<div class="form-group">
	                            	<label for="name" class="col-sm-2 control-label">市</label>
	
	                            	<div class="col-sm-8">
	                                <select id="shi" name="shi" class="form-control" onchange="shiqu()" >
	                                	<% if(!isEmpty(areaTwo)) {%>
						        		<% for(area2 in areaTwo){ %>	
										     <option value=${area2.id!} >${area2.name!}</option>
										<%}%>
										<%}%>	
						        	</select>
                            		</div>
                        	</div>
                        	
                        	<div class="form-group">
	                            	<label for="name" class="col-sm-2 control-label">镇/区</label>
	
	                            	<div class="col-sm-8">
	                                <select id="qu" name="qu" class="form-control">
	                                	<% if(!isEmpty(areaThree)) {%>
						        		<% for(area3 in areaThree){ %>	
										     <option value=${area3.id!} >${area3.name!}</option>
										<%}%>
										<%}%>	
						        	</select>
                            		</div>
                        	</div>
                        <div class="form-group">
                            <label for="address" class="col-sm-2 control-label">收货地址</label>

                            <div class="col-sm-8">
                                <input type="text" id="address" name="address" class="form-control"
                                 placeholder="收货地址" maxlength="50">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="address" class="col-sm-2 control-label">托寄物型号</label>

                            <div class="col-sm-8">
                                <input type="text" id="mailingModel" name="mailingModel" class="form-control"
                                 placeholder="托寄物型号" maxlength="20">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="address" class="col-sm-2 control-label">尺寸（长宽高）</label>

                            <div class="col-sm-8">
                                <input type="text" id="size" name="size" class="form-control"
                                placeholder="尺寸（长宽高）" maxlength="20" data-parsley-pattern="/^[\d+\*]+$/">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="address" class="col-sm-2 control-label">宝贝总数量</label>

                            <div class="col-sm-8">
                                <input type="text" id="quantity" name="quantity" class="form-control"
                                 placeholder="宝贝总数量" data-parsley-pattern="([0-9]*)$" maxlength="20">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="address" class="col-sm-2 control-label">颜色</label>

                            <div class="col-sm-8">
                                <input type="text" id="color" name="color" class="form-control"
                                 placeholder="颜色" maxlength="20">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="type" class="col-sm-2 control-label">物流公司</label>
                            <div class="col-sm-8">
                                <select id="Logistics" name="Logistics" class="form-control">
                                    <% for(items in logistics){%>
									    <option value="${items.id}">${items.name}</option>
									<%}%>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>

                        <div>
                            <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
                        </div>
                    </div>
                </div>
            </form>
        </section>

    </div>
</div>
<a class="exit-offscreen"></a>
<script language="JavaScript">

    $(document).ready(function () {
        $('#orderAddForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
                form.find("button:submit").button("loading");
                
            },
            success: function (data, statusText, xhr, form) {
                if (data.code==0) {
                    Toast.success(data.msg);
                    setTimeout(function () {
                        $("#goback").trigger("click");
                    }, 1000);
                } else {
                    Toast.error(data.msg);
                }
                form.find("button:submit").button("reset");
            }
        });
        $(".btn-parsley").click(function(){
       	 if($("#shi").val()==null){
                console.log($("#sheng").val());
            	$("#area").val($("#sheng").val());
            }else{
            	 if($("#qu").val()==null){
	                	$("#area").val($("#shi").val());
            	 }else{
            		$("#area").val($("#qu").val());
            	 }
            }
       })
    });
    
    function shengfen(){
    	$("#shi").empty();
    	$("#qu").empty();
    	$("#money").html("");
    	$.post("${base}/platform/losys/taobao/order/child" , {areaId: $("#sheng").val()}, function (data) {
    		$.each(data, function(index,values){
    			$("#shi").append("<option value='"+values.id+"'>"+values.name+"</option>");
    			
    		});
    		child(data[0].id);
        });
		
	}
	
	function shiqu() {
		$("#qu").empty();
		$.post("${base}/platform/losys/taobao/order/child" , {areaId: $("#shi").val(),  logisticsId: $("#Logistics").val()}, function (data) {
    		$.each(data, function(index,values){
    			$("#qu").append("<option value='"+values.id+"'>"+values.name+"</option>");
    		});
    		
        }); 
	}
	
	function child(areaId) {
		$("#qu").empty();
		$.post("${base}/platform/losys/taobao/order/child" , {areaId: areaId, logisticsId: $("#Logistics").val()}, function (data) {
    		$.each(data, function(index,values){
    			$("#qu").append("<option value='"+values.id+"'>"+values.name+"</option>");
    		});
    		
        }); 
	}
</script>

<%}%>